package com.only4play.practice.template.core.entity;


import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.only4play.codegen.processor.TypeConverter;
import com.only4play.codegen.processor.api.*;
import com.only4play.codegen.processor.controller.GenController;
import com.only4play.codegen.processor.creator.GenCreator;
import com.only4play.codegen.processor.dto.GenDto;
import com.only4play.codegen.processor.entitymapper.GenObjectMapper;
import com.only4play.codegen.processor.mapper.GenMapper;
import com.only4play.codegen.processor.query.GenQuery;
import com.only4play.codegen.processor.service.GenService;
import com.only4play.codegen.processor.service.GenServiceImpl;
import com.only4play.codegen.processor.updater.GenUpdater;
import com.only4play.codegen.processor.vo.GenVo;
import com.only4play.codegen.support.annotation.FieldDesc;
import com.only4play.codegen.support.constants.ValidStatus;
import com.only4play.codegen.support.model.BaseEntity;
import com.only4play.practice.common.enums.asset.InputType;
import com.only4play.practice.common.other.CodeValue;
import lombok.Data;

import javax.validation.constraints.NotEmpty;
import java.util.List;
@GenCreator(pkgName = "com.only4play.practice.template.model.creator")
@GenUpdater(pkgName = "com.only4play.practice.template.model.updater")
// findById方法
@GenVo(pkgName = "com.only4play.practice.template.model.vo")
// findByPage方法
@GenQuery(pkgName = "com.only4play.practice.template.model.query")
@GenCreateRequest(pkgName = "com.only4play.practice.template.model.request")
@GenUpdateRequest(pkgName = "com.only4play.practice.template.model.request")
@GenQueryRequest(pkgName = "com.only4play.practice.template.model.request")
@GenResponse(pkgName = "com.only4play.practice.template.model.response")
@GenDto(pkgName = "com.only4play.practice.template.model.dto")

@GenFeign(pkgName = "com.only4play.practice.template.model.feign")


// 生成serviceImpl
@GenObjectMapper(pkgName = "com.only4play.practice.template.entitymapper")
// 生成serviceImpl
@GenMapper(pkgName = "com.only4play.practice.template.core.mapper")
@GenService(pkgName = "com.only4play.practice.template.core.service")
@GenServiceImpl(pkgName = "com.only4play.practice.template.core.service.impl")

@GenController(pkgName = "com.only4play.practice.template.core.controller")
@Data
public class TemplateItem extends BaseEntity {

  @NotEmpty(message = "模板项名称不能为空")
  @FieldDesc(name = "名称")
  private String name;

  @FieldDesc(name = "输入类型")
  @TypeConverter(toTypeFullName = "java.lang.Integer")
  private InputType inputType;

  @FieldDesc(name = "占位符")
  private String placeholder;

  @FieldDesc(name = "编码")
  private String code;

  @FieldDesc(name = "创建人")
  private String createUser;

  @FieldDesc(name = "排序号")
  private Integer sortNum;

  @FieldDesc(name = "备注")
  private String remark;

  @FieldDesc(name = "是否必填")
  private ValidStatus requireFlag;

  @FieldDesc(name = "关联字典的id")
  private Long dictId;

  @TableField(typeHandler = JacksonTypeHandler.class) // EnterpriseRouter
  @FieldDesc(name = "开发扩展字段")
  private List<CodeValue> extList;


  @FieldDesc(name = "状态")
  private ValidStatus validStatus;
  public void init() {
    setValidStatus(ValidStatus.VALID);
  }

  public void valid(){
    setValidStatus(ValidStatus.VALID);
  }

  public void invalid(){
    setValidStatus(ValidStatus.INVALID);
  }
}
